
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.TimePickerMixin = exports.sharedProps = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _utils = require('./utils');

const _string = require('../utils/format/string');

const _shared = require('../picker/shared');

const _picker = _interopRequireDefault(require('../picker'));

const sharedProps = (0, _extends2.default)({}, _shared.pickerProps, {
  value: null,
  filter: Function,
  showToolbar: {
    type: Boolean,
    default: true,
  },
  formatter: {
    type: Function,
    default: function _default(type, value) {
      return value;
    },
  },
});
exports.sharedProps = sharedProps;
const TimePickerMixin = {
  data: function data() {
    return {
      innerValue: this.formatValue(this.value),
    };
  },
  computed: {
    originColumns: function originColumns() {
      const _this = this;

      return this.ranges.map((_ref) => {
        const { type } = _ref;
        const rangeArr = _ref.range;
        let values = (0, _utils.times)(rangeArr[1] - rangeArr[0] + 1, (index) => {
          const value = (0, _string.padZero)(rangeArr[0] + index);
          return value;
        });

        if (_this.filter) {
          values = _this.filter(type, values);
        }

        return {
          type,
          values,
        };
      });
    },
    columns: function columns() {
      const _this2 = this;

      return this.originColumns.map((column) => ({
        values: column.values.map((value) => _this2.formatter(column.type, value)),
      }));
    },
  },
  watch: {
    columns: 'updateColumnValue',
    innerValue: function innerValue(val) {
      this.$emit('input', val);
    },
  },
  mounted: function mounted() {
    const _this3 = this;

    this.updateColumnValue();
    this.$nextTick(() => {
      _this3.updateInnerValue();
    });
  },
  methods: {
    // @exposed-api
    getPicker: function getPicker() {
      return this.$refs.picker;
    },
    onConfirm: function onConfirm() {
      this.$emit('confirm', this.innerValue);
    },
    onCancel: function onCancel() {
      this.$emit('cancel');
    },
  },
  render: function render() {
    const _this4 = this;

    const h = arguments[0];
    const props = {};
    Object.keys(_shared.pickerProps).forEach((key) => {
      props[key] = _this4[key];
    });
    return h(_picker.default, {
      ref: 'picker',
      attrs: {
        columns: this.columns,
      },
      on: {
        change: this.onChange,
        confirm: this.onConfirm,
        cancel: this.onCancel,
      },
      props: (0, _extends2.default)({}, props),
    });
  },
};
exports.TimePickerMixin = TimePickerMixin;
